home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / video / fly8111-.000 / fly8111- / fly8 / MSDOS / grfast.c < prev    next >
C/C++ Source or Header  |  1979-12-31  |  5KB  |  290 lines

  1. /* --------------------------------- grfast.c ------------------------------- */
  2.  
  3. /* This is part of the flight simulator 'fly8'.
  4.  * Author: Eyal Lebedinsky (eyal@ise.canberra.edu.au).
  5. */
  6.  
  7. /* Vga graphics driver, uses low level graphics primitives, 256 colors only.
  8. */
  9.  
  10. #undef USECLEAR
  11.  
  12. #include "fly.h"
  13. #include "gr.h"
  14.  
  15. #include <conio.h>
  16.  
  17.  
  18. #ifdef DEBUG_GR
  19. extern void    FAR GrfMoveS3 (int x1, int y1);
  20. extern void    FAR GrfDrawS3 (int x2, int y2, Uint c);
  21. #endif
  22.  
  23. extern void far _fastcall _GrSetColor (int color, int r, int g, int b);
  24.  
  25. extern void    FAR LogStats (void);
  26. extern Ulong    FAR _BankSwitches;
  27.  
  28. #define DOSYNC        0x0001
  29. #define BIGPAGE        0x0006
  30. #define POSTSYNC    0x0008
  31. #define INITED        0x1000
  32.  
  33. #define GRF_STATS    (GRT_MASK+1)
  34.  
  35. #define MAX_SYNC_WAIT    1000L    /* 1 second is long enough */
  36.  
  37. static int    FAR width = 0, FAR height = 0;
  38. static long    FAR pagesize = 0L;
  39. static long    FAR psize[] = {0L, 512L*1024L, 1024L*1024L, 2048L*1024L};
  40.  
  41. LOCAL_FUNC int FAR
  42. GrfSetActive (int page)
  43. {
  44.     GrSetActive (page * pagesize);
  45.     return (0);
  46. }
  47.  
  48. LOCAL_FUNC int FAR
  49. GrfSetVisual (int page)        /* done */
  50. {
  51.     Ulong    lasttime;
  52.     int    ret;
  53.     int    port;
  54.  
  55.     if (2 == CS->device->colors)
  56.         port = 0x3ba;        /* monochrome */
  57.     else
  58.         port = 0x3da;        /* colour */
  59.     lasttime = st.lasttime;
  60.  
  61.     if (CS->device->flags & DOSYNC) {
  62.         while (inp (port) & 0x01) {    /* wait for Display Enabled */
  63.             sys_poll (31);
  64.             if (st.lasttime - lasttime > MAX_SYNC_WAIT) {
  65.                 LogPrintf ("%s: sync timed out\n", Gr->name);
  66.                 die ();
  67.             }
  68.         }
  69.     }
  70.  
  71.     ret = GrSetVisual (page * pagesize);
  72.  
  73.     if (CS->device->flags & (DOSYNC|POSTSYNC)) {
  74.         while (inp (port) & 0x08) {    /* wait for Vert Sync*/
  75.             sys_poll (32);
  76.             if (st.lasttime - lasttime > MAX_SYNC_WAIT) {
  77.                 LogPrintf ("%s: sync timed out\n", Gr->name);
  78.                 die ();
  79.             }
  80.         }
  81.         while (!(inp (port) & 0x08)) {    /* wait for Vert Sync end */
  82.             sys_poll (33);
  83.             if (st.lasttime - lasttime > MAX_SYNC_WAIT) {
  84.                 LogPrintf ("%s: sync timed out\n", Gr->name);
  85.                 die ();
  86.             }
  87.         }
  88.     }
  89.     return (ret);
  90. }
  91.  
  92. #undef MAX_SYNC_WAIT
  93.  
  94. LOCAL_FUNC int FAR
  95. GrfSetWriteMode (int mode)
  96. {
  97.     switch (mode) {
  98.     default:
  99.     case T_MSET:
  100.         mode = 0;
  101.         break;
  102.     case T_MOR:
  103.         mode = GrOR;
  104.         break;
  105.     case T_MXOR:
  106.         mode = GrXOR;
  107.         break;
  108.     }
  109.     GrSetWriteMode (mode);
  110.     return (0);
  111. }
  112.  
  113. LOCAL_FUNC int FAR
  114. GrfSetPalette (int index, long c)
  115. {
  116.     _GrSetColor (index, C_RGB_R (c), C_RGB_G (c), C_RGB_B (c));
  117.     return (0);
  118. }
  119.  
  120. LOCAL_FUNC int FAR
  121. GrfOptions (char *options)
  122. {
  123.     char        *p;
  124.     struct chip    *c;
  125.     long        temp;
  126.  
  127.     if (F(p = get_piarg (options, 1)))
  128.         return (1);
  129.     for (c = chips;; ++c) {
  130.         if (!c->name) {
  131.             LogPrintf ("Bad video type %s\n", p);
  132.             STRfree (p);
  133.             return (1);
  134.         }
  135.         if (!stricmp (p, c->name)) {
  136.             Gr->flags |= c->type;
  137.             break;
  138.         }
  139.     }
  140.     STRfree (p);
  141.     if (get_arg (options, "stats"))
  142.         Gr->flags |= GRF_STATS;
  143.  
  144. #ifdef DEBUG_GR
  145.     if (get_arg (options, "accel")) {
  146.         Gr->DrawTo = GrfDrawS3;
  147.         Gr->MoveTo = GrfMoveS3;
  148.     } else if (get_arg (options, "usec")) {
  149.         Gr->DrawTo = GrDrawToC;
  150.         Gr->MoveTo = GrMoveToC;
  151.     } else if (get_arg (options, "usebasic")) {
  152.         Gr->DrawTo = GrDrawTo;
  153.         Gr->MoveTo = GrMoveTo;
  154.     } else {
  155.         Gr->DrawTo = GrDrawToA;
  156.         Gr->MoveTo = GrMoveToA;
  157.     }
  158. #endif
  159.  
  160.     if (!get_narg (options, "shutters=", &temp))
  161.         st.misc[7] = (int)temp;
  162.     else
  163.         st.misc[7] = 0;
  164.  
  165.     return (0);
  166. }
  167.  
  168. LOCAL_FUNC int FAR
  169. GrfInit (DEVICE *dev, char *options)
  170. {
  171.     int    i;
  172.     int    row;
  173.  
  174.     if (GrfOptions (options))
  175.         return (1);
  176.  
  177.     if (dev->sizex == 0 || dev->sizey == 0) {
  178.         LogPrintf ("Bad WxH in .vmd file\n");
  179.         return (1);
  180.     }
  181.     width = dev->sizex;
  182.     height = dev->sizey;
  183.     pagesize = T(i = dev->flags & BIGPAGE)
  184.             ? psize[i/2]
  185.             : (long)width * (long)height;
  186.     if (!dev->mode) {
  187.         LogPrintf ("Must have video mode in .vmd file\n");
  188.         return (1);
  189.     }
  190.     GrSetXY (dev->sizex, dev->sizey);
  191.     GrSetBiosMode (dev->mode);
  192.     GrSetType (Gr->flags & GRT_MASK, (int)(dev->npages*pagesize/1024L),
  193.         dev->sizex);
  194.  
  195. #ifdef DEBUG_GR
  196.     while (GrAllocCell () >= 0)        /* get 2-255 */
  197.         ;
  198. #endif
  199.  
  200.     if (GrfSetVisual (0))
  201.         dev->npages = 1;
  202.  
  203.     GrfSetWriteMode (T_MSET);
  204.     GrfSetPalette (CC_BLACK, C_BLACK);
  205.  
  206.     for (i = dev->npages; --i >= 0;) {
  207.         GrfSetActive (i);
  208. #if 0
  209.         GrClear (0, 0, dev->sizex, dev->sizey, st.colors[CC_BLACK]);
  210. #else
  211.         for (row = 0; row < dev->sizey; ++row) {
  212.             Gr->MoveTo (0, row);
  213.             Gr->DrawTo (dev->sizex-1, row, st.colors[CC_BLACK]);
  214.         }
  215. #endif
  216.     }
  217.  
  218.     Gr->flags |= INITED;
  219.  
  220.     return (0);
  221. }
  222.  
  223. LOCAL_FUNC void FAR
  224. GrfTerm (DEVICE *dev)
  225. {
  226.     if (!(Gr->flags & INITED))
  227.         return;
  228.     Gr->flags &= ~INITED;
  229.  
  230.     LogPrintf ("BankSwitches %s\n", show_ul (_BankSwitches));
  231.     if (Gr->flags & GRF_STATS)
  232.         LogStats ();
  233.  
  234.     GrSetType (GRT_NONE, 256, 200);
  235.     GrSetBiosMode (0x03);        /* text 80x25 */
  236. }
  237.  
  238. #ifdef USECLEAR
  239. LOCAL_FUNC void FAR
  240. GrfClear (SCREEN *scr)
  241. {
  242.     GrClear (scr->minx, scr->miny, scr->sizex, scr->sizey, scr->BgColor);
  243. }
  244. #endif
  245.  
  246. LOCAL_FUNC int FAR
  247. GrfShutters (int eye)
  248. {
  249.     if (st.misc[7]) {
  250.         if (eye >= 0)
  251.             outp (st.misc[7]+4, 1+2*eye);
  252.         else if (-1 == eye)
  253.             outp (st.misc[7]+4, 1);        /* on */
  254.         else if (-2 == eye)
  255.             outp (st.misc[7]+4, 0);        /* off */
  256.         return (0);                /* have shutters */
  257.     } else
  258.         return (1);                /* no shutters */
  259. }
  260.  
  261.  
  262. struct GrDriver NEAR GrFast = {
  263.     "GrFast",
  264.     0,
  265.     NULL,    /* extra */
  266.     0,
  267.     GrfInit,
  268.     GrfTerm,
  269.     GrMoveToA,
  270.     GrDrawToA,
  271.     GrfSetVisual,
  272.     GrfSetActive,
  273. #ifdef USECLEAR
  274.     GrfClear,
  275. #else
  276.     0,    /* GrfClear() too slow */
  277. #endif
  278.     GrfSetWriteMode,
  279.     GrfSetPalette,
  280.     GrEllipse,
  281.     0,    /* Flush */
  282.     GrfShutters
  283. };
  284. #undef DOSYNC
  285. #undef BIGPAGE
  286. #undef POSTSYNC
  287. #undef GRF_STATS
  288. #undef INITED
  289. #undef MAX_SYNC_WAIT
  290.